﻿using System;
using System.Data.SqlClient;
using System.Diagnostics;

namespace SQLDeploy.Data.Connections
{
    public class SQLServerConnection : _BaseSQLConnection
    {
        public SQLServerConnection() : base() {}

        public SQLServerConnection(string Name) : base(Name)
        {
        }

        public SQLServerConnection(string Name, string Data)
            : base(Name, Data)
        {
           
        }

        public override string Usage
        {
            get
            {
                return Properties.Resources.SqlDatabaseConnection_Usage;
            }
        }

        protected internal override bool performSQLConnectionTypeValidation(ref SqlConnection connection)
        {
            try
            {
                SqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT IS_SRVROLEMEMBER('sysadmin')";
                object result = cmd.ExecuteScalar();
                return (result != null && result is int && (int)result != 0);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return false;
            }
        }

    }
}
